package orange.play.c2dm;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import orange.play.c2dm.utils.AuthenticationUtil;
import orange.play.c2dm.utils.MessageUtil;
import orange.play.c2dm.utils.ServerConfiguration;

/**
 * Servlet implementation class C2DMServer
 */
public class C2DMServer extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String Token;
	private String registrationId;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public C2DMServer() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (request.getParameter("message") != null)
			MessageUtil.sendMessage(ServerConfiguration.AUTHENTICATION_TOKEN, ServerConfiguration.REGISTRATION_ID,
					request.getParameter("message"));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (request.getParameter("registrationId") != null)
			registrationId = request.getParameter("registrationId");
	}

}
